//
// Created by Administrator on 2021/6/15.
//
#include <vector>
#include <iostream>

using namespace std;

class Solution {
public:
    int peakIndexInMountainArray(vector<int> &arr) {
        int left = 1, right = (int)arr.size() - 2, ans = 0;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (arr[mid] > arr[mid + 1]) {
                ans = mid;
                right = mid - 1;
            }
            else {
                left = mid + 1;
            }
        }
        return ans;
    }
    int peakIndexInMountainArray2(vector<int> &arr) {
        int lhs = 0, rhs = (int) arr.size() - 1;
        while (lhs < rhs) {
            int mid = lhs + (rhs - lhs) / 2;
            if (arr[mid] < arr[mid + 1]) lhs = mid + 1; // 题目明确不会有相等的  只考虑大 或者小
            else rhs = mid;
        }
        return lhs;
    }

};

int main() {
    vector<int> arr{0, 2, 1, 0};
    Solution sol;
    cout << sol.peakIndexInMountainArray2(arr) << endl;
    return 0;
}